home *** CD-ROM | disk | FTP | other *** search
/ Interactive Web Graphics with Shout 3D / Interactive Web Graphics With Shout 3D.iso / mac / Shout3Ddemo / Shout3d_runtime / codebase / applets / SelectAPanoramaPanel.java < prev    next >
Text File  |  2000-09-01  |  5KB  |  171 lines

  1. /**    
  2.     Company:        Eyematic Interfaces
  3.     Project:        Shout3D 2.0 Sample Code
  4.     Class:            ExaminePanel
  5.     Date:            April 3, 2000
  6.     Description:    Class for ExaminePanel
  7.     (C) Copyright Eyematic Interfaces, Inc. - 1997/1998/1999/2000 - All rights reserved
  8.  */
  9.  
  10. package applets;
  11.  
  12. import java.applet.*;
  13. import java.awt.*;
  14. import shout3d.core.*;
  15. import shout3d.*;
  16.  
  17. import custom_nodes.*;
  18.  
  19. /**
  20.  * A SelectAPanoramaPanel.
  21.  * 
  22.  * @author Dave Westwood
  23.  * @author Paul Isaacs
  24.  * @author Jim Stewartson
  25.  */
  26.  
  27. public class SelectAPanoramaPanel extends ExaminePanel implements DeviceObserver {
  28.     
  29.         
  30.     Panorama panorama;
  31.     EnvironmentCubeMap envCubeMap;
  32.     MultiMesh[] meshes;
  33.     
  34.     /**
  35.      * Constructs me
  36.      */
  37.     public SelectAPanoramaPanel(Shout3DApplet applet){
  38.         super(applet);
  39.     }
  40.     /**
  41.      * Constructs me
  42.      */
  43.     public SelectAPanoramaPanel(Shout3DApplet applet, int width, int height){
  44.         super(applet,width, height);
  45.     }
  46.     
  47.     /**
  48.      * Remove observers when done with the panel
  49.      */
  50.     public void finalize()throws Throwable {
  51.         applet.getDeviceListener().removeDeviceObserver(this, "DeviceInput");
  52.         applet.getRenderer().removeRenderObserver(this);        
  53.         super.finalize();
  54.     }
  55.     
  56.     /**
  57.      * Overrides Shout3DPanel.customInitialize()
  58.      */
  59.     public void customInitialize() {
  60.         super.customInitialize();
  61.         
  62.         // register for device input
  63.         applet.getDeviceListener().addDeviceObserver(this, "DeviceInput", null);
  64.         // register for rendering notification
  65.         applet.getRenderer().addRenderObserver(this, null);    
  66.         
  67.         Searcher mySearcher = getNewSearcher();
  68.         
  69.         // reference to Panorama
  70.         mySearcher.setType("Panorama");
  71.         Node[] path = mySearcher.searchFirst(getScene());
  72.         if (path!=null && path.length>0){
  73.             panorama = (Panorama)path[path.length-1];
  74.         }
  75.         
  76.         // reference to EnvironmentCubeMap used in a Panorama
  77.         mySearcher.setType("EnvironmentCubeMap");
  78.         path = mySearcher.searchFirst(getScene());
  79.         if (path!=null && path.length>0){
  80.             envCubeMap = (EnvironmentCubeMap)path[path.length-1];
  81.         }
  82.         
  83.         // reference to env mapped meshes
  84.         mySearcher.setType("MultiMesh");
  85.         Node[][] paths = mySearcher.searchAll(getScene());
  86.         if (paths!=null && paths.length>0){
  87.             meshes = new MultiMesh[paths.length];
  88.             for (int i = 0; i < paths.length; i++){
  89.                 meshes[i] = (MultiMesh)paths[i][paths[i].length-1];
  90.             }
  91.         }
  92.         
  93.         // Turn off antialiasing so that the env map will change even if 
  94.         // camera is still
  95.         mySearcher.setType("StillCamProgAntialias");
  96.         path = mySearcher.searchFirst(getScene());
  97.         if (path!=null && path.length>0){
  98.             StillCamProgAntialias aa = (StillCamProgAntialias)path[path.length-1];
  99.             aa.enabled.setValue(false);
  100.         }
  101.         
  102.     }
  103.         
  104.     public boolean onDeviceInput(DeviceInput di, Object userData){
  105.         return super.onDeviceInput(di, userData);
  106.     }
  107.     ImageTexture itex;
  108.  
  109.     /**
  110.      * Set the EnvironmentCubeMap textures and/or change bilinear filtering 
  111.      * if we are waiting to do so.
  112.      * 
  113.      * Note that no onPreRender() method is implemented in this class,
  114.      * even though it is required for all classes implementing RenderObserver.
  115.      * This is because the super class implements RenderObserver fully 
  116.      * and onPreRender is inherited.  
  117.      * Hence this class needs only to override the onPostRender() method, 
  118.      * making sure to call super.onPostRender(r,userData) within the body 
  119.      * of the method.
  120.      */
  121.     public void onPostRender(Renderer r, Object userData){
  122.         super.onPostRender(r, userData);
  123.         if (envCubeMap!= null && set_envmap_urls){
  124.             itex = (ImageTexture) envCubeMap.frontTexture.getValue();
  125.             if (itex != null)
  126.                 itex.url.setValue(new String[]{frontmap});
  127.             itex = (ImageTexture) envCubeMap.rightTexture.getValue();
  128.             if (itex != null)
  129.                 itex.url.setValue(new String[]{rightmap});
  130.             itex = (ImageTexture) envCubeMap.backTexture.getValue();
  131.             if (itex != null)
  132.                 itex.url.setValue(new String[]{backmap});
  133.             itex = (ImageTexture) envCubeMap.leftTexture.getValue();
  134.             if (itex != null)
  135.                 itex.url.setValue(new String[]{leftmap});
  136.             itex = (ImageTexture) envCubeMap.upTexture.getValue();
  137.             if (itex != null)
  138.                 itex.url.setValue(new String[]{upmap});
  139.             itex = (ImageTexture) envCubeMap.downTexture.getValue();
  140.             if (itex != null)
  141.                 itex.url.setValue(new String[]{downmap});
  142.             set_envmap_urls = false;
  143.         }
  144.         if (envCubeMap != null && set_bilerp_enabled){
  145.             envCubeMap.bilinearFilteringEnabled.setValue(bilerp_enabled);
  146.             panorama.bilinearFilteringEnabled.setValue(bilerp_enabled);
  147.             set_bilerp_enabled = false;
  148.         }
  149.     }
  150.     
  151.     boolean set_envmap_urls = false;
  152.     String frontmap, rightmap, backmap, leftmap, upmap, downmap;
  153.     public void setEnvMaps(String _frontmap, String _rightmap, String _backmap, String _leftmap, 
  154.                            String _upmap, String _downmap){
  155.         frontmap    = _frontmap;
  156.         rightmap    = _rightmap;
  157.         backmap        = _backmap;
  158.         leftmap        = _leftmap;
  159.         upmap        = _upmap;
  160.         downmap        = _downmap;
  161.         set_envmap_urls     = true;
  162.     }
  163.     
  164.     boolean set_bilerp_enabled  = false;
  165.     boolean bilerp_enabled      = true;
  166.     public void setBilerpEnabled(boolean _bilerp_enabled){
  167.         set_bilerp_enabled      = true;
  168.         bilerp_enabled          = _bilerp_enabled;
  169.     }
  170. }
  171.